package com.cn.crmsystem.common;
import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
	@Configuration
	@EnableSwagger2
	@EnableWebMvc
	public class SwaggerConfig {
		@Bean
		public Docket createRestApi() {
			System.out.println("-----SwaggerConfig-------------------------");
			return new Docket(DocumentationType.SWAGGER_2)
					.enable(true)          // 是否禁用swagger
					.useDefaultResponseMessages(false)
					.apiInfo(apiInfo())
					.select()
					.apis(RequestHandlerSelectors.basePackage("com.cn.crmsystem.controller"))
					.paths(PathSelectors.any())
					.build();
		}
		private ApiInfo apiInfo() {
			System.out.println("++++++=++++++++++++++++++++++++SwaggerConfig apiInfo----------------------------");
			return new ApiInfoBuilder()
					.title("swagger API文档")
					.description("测试接口文档")
					.version("1.0")
					.build();
		}
		/**
		 * 解决swagger-ui.html 404无法访问的问题
		 */
	/*	public void addResourceHandlers(ResourceHandlerRegistry registry) {
			System.out.println("++++++=++++++++++++++++++++++++addResourceHandlerso----------------------------");
			registry
					.addResourceHandler("swagger-ui.html")
					.addResourceLocations("classpath:/META-INF/resources/");
			registry
					.addResourceHandler("/webjars/**")
					.addResourceLocations("classpath:/META-INF/resources/webjars/");
		}*/
		/*public void addResourceHandlers(ResourceHandlerRegistry registry) {
			// 解决静态资源无法访问
			registry.addResourceHandler("/**")
					.addResourceLocations("classpath:/static/");
			// 解决swagger无法访问
			registry.addResourceHandler("/swagger-ui.html")
					.addResourceLocations("classpath:/META-INF/resources/");
			// 解决swagger的js文件无法访问
			registry.addResourceHandler("/webjars/**")
					.addResourceLocations("classpath:/META-INF/resources/webjars/");
		}*/
	}
